package com.iofiledDemo;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class A2 {

    public static void main(String[] args) {

        A2 a2 = new A2();

        String filePath = "D:/upload/ioFile.txt";

        String content = "今天天气很好";
        a2.wirteFile(filePath,content);


    }




    public void wirteFile(String filePath,String content){
        FileOutputStream fos = null;


        try {
            fos = new FileOutputStream(filePath,true);

            //把string转换为byte数组；
            byte[] array = content.getBytes();

            try {

                fos.write(array);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }finally {

            if(fos !=null){

                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }


}
